from common import *

from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure

from cStringIO import StringIO

import pylab
import os

default_data = {
    'title':'title',
    'xlabel':'xlabel',
    'ylabel':'ylabel' }

def setup(data = default_data):
    import wx
    # title
    dlg = wx.TextEntryDialog(
        None, 'Title',
        'Configure Process', data['title'])
    if dlg.ShowModal() == wx.ID_OK:
        data['title'] = dlg.GetValue()
    dlg.Destroy()
    # xlabel
    dlg = wx.TextEntryDialog(
        None, 'xLabel',
        'Configure Process', data['xlabel'])
    if dlg.ShowModal() == wx.ID_OK:
        data['xlabel'] = dlg.GetValue()
    dlg.Destroy()
    # ylabel
    dlg = wx.TextEntryDialog(
        None, 'ylabel',
        'Configure Process', data['ylabel'])
    if dlg.ShowModal() == wx.ID_OK:
        data['ylabel'] = dlg.GetValue()
    dlg.Destroy()

    return data

def plotpng_xFunc(in_x, in_f_x , out_png, data = default_data):

    while True:
        fig = Figure()
        canvas = FigureCanvas(fig)
        ax = fig.add_subplot(111)
        
        x = in_x()
        f_x = in_f_x()
        
        ax.plot(x,f_x)
        ax.set_title(data['title'])
        ax.set_xlabel(data['xlabel'])
        ax.set_ylabel(data['ylabel'])

        s = StringIO()
        canvas.print_figure(s)

        out_png(s.getvalue())

